package com.bang.daybreak.common.config;

import io.swagger.annotations.ApiOperation;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Profile;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * <p>
 * RESTful 服务 API 管理框架 Swagger 配置初始化
 * </p>
 *
 * @version 1.0
 * @author : wdj
 * @since : 2019/7/23 0023 下午 14:06
 */
@Configuration
@EnableSwagger2
@Profile({"dev", "test"})
public class SwaggerAutoConfiguration {

    @Bean
    public Docket api() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                //限制只有在方法加@ApiOperation才添加到swagger，默认是都添加的
                .apis(RequestHandlerSelectors.withMethodAnnotation(ApiOperation.class))
                .paths(PathSelectors.any()).build().useDefaultResponseMessages(false);
    }

    /**
     * 获取swagger ApiInfo
     *
     * @return
     */
    private static ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("民航")
                .description("swagger")
                .termsOfServiceUrl("localhost:8080")
                .version("1.0")
                .contact(new Contact("wangdejian", "localhost:8859/doc.html", "wangdejian@bang.com.cn"))
                .build();
    }

}
